package ylsb.service;


import org.springframework.stereotype.Service;
import ylsb.dao.HaocaiyinjinMapper;
import ylsb.dao.TiwaizhenduanMapper;
import ylsb.model.Haocaiyinjin;
import ylsb.model.HaocaiyinjinExample;
import ylsb.model.Tiwaizhenduan;
import ylsb.model.TiwaizhenduanExample;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

@Service
public class TiwaizhenduanService {

    @Resource
    TiwaizhenduanMapper ddMapper;

    public List<Map<String, Object>> findDaochuPinzhongAll(String ppxiangmuId){
        return ddMapper.findDaochuPinzhongAll(ppxiangmuId);
    }
    public List<Tiwaizhenduan> findAllByXiangmuId(String mmxiangmuId) {
        TiwaizhenduanExample mmExample = new TiwaizhenduanExample();
        TiwaizhenduanExample.Criteria criteria = mmExample.createCriteria();
        criteria.andXiangmuidEqualTo(mmxiangmuId);
        return ddMapper.selectByExample(mmExample);
    }
    public List<Map<String, Object>> findPinguiResult(String ppxiangmuId){
        return ddMapper.findPinguiResult(ppxiangmuId);
    }

    public List<Map<String, Object>> findPinpaiResultByPinzhong(String ppxiangmuId,String ppuserId,String mmPinzhongOne){
        return ddMapper.findPinpaiResultByPinzhong(ppxiangmuId,ppuserId,mmPinzhongOne);
    }

    public boolean add (Tiwaizhenduan ddTiwaizhenduan){
        return ddMapper.insert(ddTiwaizhenduan)==1;
    }

    public List<Map<String, Object>> findPinpaiByPinzhong(String mmPinzhongOne){
        return ddMapper.findPinpaiByPinzhong(mmPinzhongOne);
    }

    public List<Map<String, Object>> findPinzhongAll(String ppxiangmuId,int ppPageIndex, int ppPageSize){
        int mmStartIndex = (ppPageIndex - 1) * ppPageSize;
        return ddMapper.findPinzhongAll(ppxiangmuId,mmStartIndex,ppPageSize);
    }

    public Integer getTiwaizhenduanlist(String ppxiangmuId,int ppPageIndex, int ppPageSize) {
        Object mmCount = ddMapper.getTiwaizhenduanlist(ppxiangmuId,ppPageIndex,ppPageSize);
        return mmCount == null ? 0 : Integer.parseInt(mmCount.toString());
    }

    public List<Map<String, Object>> findTiwaizhenduanlist(String ppxiangmuId,int ppPageIndex, int ppPageSize){
        int mmStartIndex = (ppPageIndex - 1) * ppPageSize;
        return ddMapper.selectByXiangmuId(ppxiangmuId,mmStartIndex,ppPageSize);
    }

    public boolean deleteByxiangmuId(String xiangmuId){
        TiwaizhenduanExample mmExample=new TiwaizhenduanExample();
        TiwaizhenduanExample.Criteria criteria=mmExample.createCriteria();
        criteria.andXiangmuidEqualTo(xiangmuId);
        return  ddMapper.deleteByExample(mmExample)>=0;
    }
    public boolean isexistByxiangmuId(String xiangmuId){
        TiwaizhenduanExample mmExample=new TiwaizhenduanExample();
        TiwaizhenduanExample.Criteria criteria=mmExample.createCriteria();
        criteria.andXiangmuidEqualTo(xiangmuId);
        return  ddMapper.selectByExample(mmExample).size()>0;
    }


    public Integer getVoteCount(String ppxiangmuId){
        List<Map<String, Object>> list=ddMapper.findPinzhongAndPinpaiByXiangmuId(ppxiangmuId);
        return list == null ? 0 : list.size();
    }

}
